/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package All.Mapper;

import All.DTO.NhomsanphamDTO;
import All.DTO.TintucDTO;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author NGUYEN DANG
 */
public class NhomSPMapper extends MapperDB
{
    public NhomSPMapper() throws Exception 
        {
		super();
	}
    public ArrayList<NhomsanphamDTO> listSanpham() throws Exception {
        ArrayList<NhomsanphamDTO> listOfInfo = new ArrayList<NhomsanphamDTO>();
        NhomsanphamDTO nhomspDTO = null;
        try{
            StringBuilder sql = new StringBuilder();
            sql.append("SELECT * FROM NhomSP");
            PreparedStatement stmt = getConnection().prepareStatement(sql.toString());
            ResultSet rs = stmt.executeQuery();
            while ((rs != null) && rs.next()) {
                    nhomspDTO = new NhomsanphamDTO();
                    initTintucDTO(nhomspDTO, rs);
                    listOfInfo.add(nhomspDTO);
            }

            stmt.close();
        }
        catch(Exception e)
        {
            throw e;
        }
        return listOfInfo;
    }

    private void initTintucDTO(NhomsanphamDTO nhomspDTO, ResultSet rs) throws SQLException {
        if ((rs != null) && (nhomspDTO != null)) 
        {   
            nhomspDTO.setIDNhomSP(rs.getString("NhomSP"));
            nhomspDTO.setTennhom(rs.getString("TenNhom"));
        }
    }
    
}
